<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<meta name="viewport"
		  content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>Cairo-个人中心</title>
  <style>
    table {
      width: 1000px;
      margin: 0;
      border-collapse: collapse;
      border: 1px black solid;
    }

    td, th {
      margin: 0;
      padding: 0;
      border: 1px black solid;
      text-align: left;
    }
  </style>
</head>
<body>
<div id="profile" th:if="${#authentication != null}">

	<!-- 账号密码登录 -->
	<div th:if="${#authentication instanceof T(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)}">
		<h2>1. 密码认证</h2>
		<div th:if="${#authentication.principal instanceof T(cn.lijiajia3515.cairo.domain.CairoAccount)}">
			<h3> 1.1 账号信息 (CairoAccount): </h3>
			<table th:if="${#authentication.principal != null}" style="border: 1px" border="1">
				<thead>
				<tr>
					<th>属性名</th>
					<th>值</th>
				</tr>
				<tr>
					<td>标识</td>
					<td th:text="${#authentication.principal.id}"></td>
				</tr>
				<tr>
					<td>登录名</td>
					<td th:text="${#authentication.principal.login}"></td>
				</tr>
				<tr>
					<td>手机号</td>
					<td th:text="${#authentication.principal.phoneNumber}"></td>
				</tr>
				<tr>
					<td>邮箱</td>
					<td th:text="${#authentication.principal.email}"></td>
				</tr>
				<tr>
					<td>昵称</td>
					<td th:text="${#authentication.principal.nickname}"></td>
				</tr>
				<tr>
					<td>头像</td>
					<td th:src="${#authentication.principal.avatarUrl}"></td>
				</tr>
				</thead>
			</table>
			<div th:if="${#authentication.principal.departments.size > 0}">
				<h3> 部门信息: </h3>

				<table border="1">
					<thead>
					<tr>
						<th>部门标识</th>
						<th>部门名称</th>
					</tr>
					<tr th:each="department:${#authentication.principal.departments}">
						<td th:text="${department.id}"></td>
						<td th:text="${department.name}"></td>
					</tr>
					</thead>
				</table>
			</div>
			<div th:if="${#authentication.principal.roles.size >0}">
				<h3> 角色信息: </h3>

				<table border="1">
					<thead>
					<tr>
						<th>角色标识</th>
						<th>角色名称</th>
					</tr>
					<tr th:each="role:${#authentication.principal.roles}">
						<td th:text="${role.id}"></td>
						<td th:text="${role.name}"></td>
					</tr>
					</thead>
				</table>
			</div>
		</div>
	</div>

	<!-- oauth2协议登录 -->
  <div
    th:if="${#authentication instanceof T(org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken)}">
    <h2>1. OAuth2 认证</h2>
    <div>
      <h3> OAuth2 Attribute: </h3>
      <h3 th:if="${#authentication.principal.attributes == null || #authentication.principal.attributes.size == 0}">无</h3>
      <table border="1" th:if="${#authentication.principal.attributes != null && #authentication.principal.attributes.size > 0}">
        <thead>
        <tr>
          <th>部门标识</th>
          <th>部门名称</th>
        </tr>
        <tr th:each="department:${#authentication.principal.attributes}">
          <td th:text="${department.key}"></td>
          <td th:text="${department.value}"></td>
        </tr>
        </thead>
      </table>
    </div>

    <div th:if="${#authentication.principal != null}">
      <div th:if="${#authentication.principal instanceof T(cn.lijiajia3515.cairo.auth.framework.security.oauth2.CairoOAuth2User)}">
        <h3> 1.2 账号信息 (CairoAccount): </h3>
        <table style="border: 1px" border="1">
          <thead>
          <tr>
            <th>属性名</th>
            <th>值</th>
          </tr>
          <tr>
            <td>标识</td>
            <td th:text="${#authentication.principal.id}"></td>
          </tr>
          <tr>
            <td>登录名</td>
            <td th:text="${#authentication.principal.login}"></td>
          </tr>
          <tr>
            <td>手机号</td>
            <td th:text="${#authentication.principal.phoneNumber}"></td>
          </tr>
          <tr>
            <td>邮箱</td>
            <td th:text="${#authentication.principal.email}"></td>
          </tr>
          <tr>
            <td>昵称</td>
            <td th:text="${#authentication.principal.nickname}"></td>
          </tr>
          <tr>
            <td>头像</td>
            <td th:text="${#authentication.principal.avatarUrl}"></td>
          </tr>
          </thead>
        </table>
        <div>
          <h2> 部门信息: </h2>
          <h3 th:if="${#authentication.principal.departments == null || #authentication.principal.departments.size == 0}">无</h3>
          <table border="1" th:if="${#authentication.principal.departments != null && #authentication.principal.departments.size > 0}">
            <thead>
            <tr>
              <th>部门标识</th>
              <th>部门名称</th>
            </tr>
            <tr th:each="department:${#authentication.principal.departments}">
              <td th:text="${department.id}"></td>
              <td th:text="${department.name}"></td>
            </tr>
            </thead>
          </table>
        </div>
        <div>
          <h2> 角色信息: </h2>
          <h3 th:if="${#authentication.principal.roles == null || #authentication.principal.roles.size == 0}">无</h3>
          <table border="1" th:if="${#authentication.principal.roles != null && #authentication.principal.roles.size > 0 }">
            <thead>
            <tr>
              <th>角色标识</th>
              <th>角色名称</th>
            </tr>
            <tr th:each="role:${#authentication.principal.roles}">
              <td th:text="${role.id}"></td>
              <td th:text="${role.name}"></td>
            </tr>
            </thead>
          </table>
        </div>
      </div>
    </div>
  </div>

  <!-- 资源服务方式登录 -->
  <div th:if="${#authentication instanceof T(org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken)}">

    <h2>1. OAuth2 客户端 认证</h2>
    <div th:if="${#authentication.principal instanceof T(org.springframework.security.oauth2.jwt.Jwt)}">
      <div th:if="${#authentication.principal.headers != null}">
        <h3> 1.1 头部信息 (Jwt Header): </h3>
        <table >
          <thead>
          <tr>
            <th>属性名</th>
            <th>值</th>
          </tr>
          <tr th:each="header : ${#authentication.principal.headers}">
            <td th:text="${header.key}" style="text-align: left">无</td>
            <td th:text="${header.value}" style="text-align: left">无</td>
          </tr>
          </thead>
        </table>
      </div>

      <div th:if="${#authentication.principal.claims != null}">
        <h3> 1.2 主体信息 (Jwt Payload): </h3>
        <table >
          <thead>
          <tr>
            <th>属性名</th>
            <th>值</th>
          </tr>
          <tr th:each="claim : ${#authentication.principal.claims}">
            <td th:text="${claim.key}" style="text-align: left">无</td>
            <td th:text="${claim.value}" style="text-align: left">无</td>
          </tr>
          </thead>
        </table>
      </div>
    </div>

    <div th:if="${#authentication.principal instanceof T(cn.lijiajia3515.cairo.security.oauth2.jwt.CairoJwtPrincipal)}">
      <div th:if="${#authentication.principal.headers != null}">
        <h3> 1.1 头部信息 (Jwt Header): </h3>
        <table >
          <thead>
          <tr>
            <th>属性名</th>
            <th>值</th>
          </tr>
          <tr th:each="header : ${#authentication.principal.headers}">
            <td th:text="${header.key}" style="text-align: left">无</td>
            <td th:text="${header.value}" style="text-align: left">无</td>
          </tr>
          </thead>
        </table>
      </div>

      <div th:if="${#authentication.principal.claims != null}">
        <h3> 1.2 主体信息 (Jwt Payload): </h3>
        <table >
          <thead>
          <tr>
            <th>属性名</th>
            <th>值</th>
          </tr>
          <tr th:each="claim : ${#authentication.principal.claims}">
            <td th:text="${claim.key}" style="text-align: left">无</td>
            <td th:text="${claim.value}" style="text-align: left">无</td>
          </tr>
          </thead>
        </table>
      </div>

      <div th:if="${#authentication.principal != null}">
        <h3> 1.3 账号信息 (CairoAccount): </h3>
        <table>
          <thead>
          <tr>
            <th>属性名</th>
            <th>值</th>
          </tr>
          <tr>
            <td>标识</td>
            <td th:text="${#authentication.principal.account.id}"></td>
          </tr>
          <tr>
            <td>登录名</td>
            <td th:text="${#authentication.principal.account.login}"></td>
          </tr>
          <tr>
            <td>手机号</td>
            <td th:text="${#authentication.principal.account.phoneNumber}"></td>
          </tr>
          <tr>
            <td>邮箱</td>
            <td th:text="${#authentication.principal.account.email}"></td>
          </tr>
          <tr>
            <td>昵称</td>
            <td th:text="${#authentication.principal.account.nickname}"></td>
          </tr>
          <tr>
            <td>头像</td>
            <td th:text="${#authentication.principal.account.avatarUrl}"></td>
          </tr>
          </thead>
        </table>
        <div >
          <h2> 部门信息: </h2>
          <h3 th:if="${#authentication.principal.account.departments == null || #authentication.principal.account.departments.size == 0 }">无</h3>
          <table border="1" th:if="${#authentication.principal.account.departments != null && #authentication.principal.account.departments.size > 0}">
            <thead>
            <tr>
              <th>部门标识</th>
              <th>部门名称</th>
            </tr>
            <tr th:each="department:${#authentication.principal.account.departments}">
              <td th:text="${department.id}"></td>
              <td th:text="${department.name}"></td>
            </tr>
            </thead>
          </table>
        </div>
        <div>
          <h2> 角色信息: </h2>
          <h3 th:if="${#authentication.principal.account.roles == null || #authentication.principal.account.roles.size == 0 }">无</h3>
          <table border="1" th:if="${#authentication.principal.account.roles != null && #authentication.principal.account.roles.size > 0}">
            <thead>
            <tr>
              <th>角色标识</th>
              <th>角色名称</th>
            </tr>
            <tr th:each="role:${#authentication.principal.account.roles}">
              <td th:text="${role.id}"></td>
              <td th:text="${role.name}"></td>
            </tr>
            </thead>
          </table>
        </div>
      </div>
    </div>
  </div>

  <br/>

	<div>
		<h2> 2. 权限信息: </h2>
		<div th:if="${#authentication.authorities.size > 0}">
			<table border="1">
				<thead>
				<tr>
					<th>角色标识</th>
				</tr>
				<tr th:each="authority:${#authentication.authorities}">
					<td th:text="${authority.authority}"></td>
				</tr>
				</thead>
			</table>
		</div>

		<div th:if="${#authentication.authorities.size == 0}">
			<h3>没有权限</h3>
		</div>
	</div>
	<br/>
	<div>
		<h2>3.凭证: </h2>
		<textarea th:text="${#authentication}" style="width: 500px; height: 500px;">空</textarea>
	</div>

</div>
</body>
</html>
